package com.wangxianseng.controller;


import com.wangxianseng.bean.ExportReq;
import com.wangxianseng.service.ReadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/ncse")
public class RecordsController {

    @Autowired
    private ReadService readService;

    @PostMapping("/export")
    public void exportExcel(@RequestBody ExportReq exportReq, HttpServletResponse response){
        try{
            readService.export(exportReq,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @PostMapping("/exportExcelWithAvg")
    public void exportExcelWithAvg(@RequestBody ExportReq exportReq, HttpServletResponse response){
        try{
            readService.exportExcelWithAvg(exportReq,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @PostMapping("/preivewExcelWithAvg")
    public List<Map<String, String>> preivewExcelWithAvg(@RequestBody ExportReq exportReq){
        try{
           return readService.preivewExcelWithAvg(exportReq);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    @PostMapping("/preview")
    public List<Map<String, String>> previewExcel(@RequestBody ExportReq exportReq){
        try{
            return readService.preivewExcel(exportReq);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
